using System;
using System.Security;
using System.Security.Cryptography;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace stsdev {
    public class StrongNameKeyBuilder {

        public static void CreateNew(string fileName) {
            CspParameters parms = new CspParameters();
            parms.KeyNumber = 2;
            RSACryptoServiceProvider provider = new RSACryptoServiceProvider(1024, parms);
            byte[] array = provider.ExportCspBlob(!provider.PublicOnly);

            using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) {
                fs.Write(array, 0, array.Length);
            }
        }

        public static void AddKeyFileToProject() {
            // Modified 20090926 - bphillips - Exit if KeyFileName is blank.
            if (string.IsNullOrEmpty(SolutionBuilder.KeyFileName)) {
                return;
            }

            // CHANGE: 090103 wictor - check so that the file is not copied to itself
            if (string.Compare(Path.GetFullPath(SolutionBuilder.KeyFileName), SolutionBuilder.KeyFileSource, true) != 0) {
                // CHANGE: 090103 wictor - overwrites any existing key files
                File.Copy(SolutionBuilder.KeyFileSource, SolutionBuilder.KeyFileName, true);
            }
            ProjectFileBuilder.AddSourceFile(SolutionBuilder.KeyFileName, SourceFileTypeEnum.None);
        }
    }
}
